package com.sg.xy.service.impl;

import com.sg.xy.dao.UserDao;
import com.sg.xy.pojo.UserInfo;
import com.sg.xy.service.UserService;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public UserInfo getByEmail(String email) {
        Optional<UserInfo> oneByEmail = userDao.findOneByEmail(email);
        return oneByEmail.isPresent()?userDao.findOneByEmail(email).get():null;
    }

    @Override
    public void save(String email, String password) {
        UserInfo userInfo = new UserInfo();
        userInfo.setEmail(email);
        userInfo.setPassword(password);
        userDao.save(userInfo);
    }
}
